package com.cs.pk.form.check;

import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;

public class VerifyListenerAdapter implements VerifyListener {
    public ICheck c;

    public VerifyListenerAdapter(ICheck c) {
	this.c = c;
    }

    public void verifyText(VerifyEvent e) {
	Text field = ((Text) e.getSource());
	GC gc = new GC(c.getCheckObject());

	if (c.verify(e)) {
	    updateBorder(gc, (Color) c.getPassObject(), field);
	} else {
	    updateBorder(gc, (Color) c.getFailObject(), field);
	}
       
    }

    private void updateBorder(GC gc, Color c, Control field) {
	gc.setBackground(c);
	Rectangle rText = field.getBounds();
	Rectangle rect1 = new Rectangle(rText.x - 1, rText.y - 1,
		rText.width + 2, rText.height + 2);
	gc.fillRectangle(rect1);
    }
}